
#include "pbm.h"

#include "xapp_osllv.h"

// these function below reserved for future completed 

#if 1 // Factory Test 
pbd_err_code_t pi_ft_start_session(uint8_t *pdata, uint16_t size)
{
//    hub_app_send_task( APP_TASK_SYSTEM_FACTORY_TEST );
    return PBD_SUCCESS;
}
pbd_err_code_t pi_ft_stop_session(uint8_t *pdata, uint16_t size)
{
//    hub_app_send_task( APP_TASK_SYSTEM_BOOT ); 
    return PBD_SUCCESS;
}

pbd_err_code_t pi_ft_set_vibrate(uint8_t *pdata, uint16_t size){

    if( size != 13 ){
        return PBD_ERR_INVALID_LENGTH;
    }

#if OSLLV_VIBRATE_TEST_DEFINED    
    uint16_t pending = uint16_decode( pdata ); 
    uint16_t on = uint16_decode( pdata + 2); 
    uint16_t off = uint16_decode( pdata + 4); 
    uint16_t repeat = uint16_decode( pdata + 6 ); 
    uint16_t delay = uint16_decode( pdata + 8);
    uint16_t cycle = uint16_decode( pdata + 10); 
    uint8_t duty = pdata[12]; 
    OSLLV_VIBRATE_TEST_HANDLE( duty, pending, on, off, repeat, delay, cycle );
    return PBD_SUCCESS;
#else 
    return PBD_ERR_SUB_FUNCTION_NOT_SUPPORTED; 
#endif 

//    xapp_alert_task_set_alert(duty, pending, on, off, repeat, delay, cycle ); 
    

    // return PBD_SUCCESS;
}

pbd_err_code_t pi_ft_set_heartrate(uint8_t *pdata, uint16_t size)
{
    return PBD_ERR_INVALID_PARAMS; 
}

// leave interface to access peripherals 
// static uint16_t alerttype = 0; 
pbd_err_code_t pi_ft_set_alert(uint8_t *pdata, uint16_t size){
    if( size != 1 ){
        return PBD_ERR_INVALID_LENGTH;
    }
    
    return PBD_SUCCESS;
}
pbd_err_code_t pi_ft_set_text(uint8_t *pdata, uint16_t size)
{
    return PBD_SUCCESS;
}

pbd_err_code_t pi_ft_set_lcd_calibrate(uint8_t *pdata, uint16_t size)
{
    if( size != 1 )
        return PBD_ERR_INVALID_LENGTH;
        
    return PBD_SUCCESS;
}

pbd_err_code_t pi_ft_query_selftest_state(uint8_t *pdata, uint16_t size, uint8_t *p_res, uint16_t *p_size)
{
    if( size != 0 )
    {
        return PBD_ERR_INVALID_LENGTH;
    }

//    p_res[0] = iqw_app_factory_test_get_state();
    *p_size = 1;
    
    return PBD_SUCCESS;
}
pbd_err_code_t pi_ft_query_selftest_result(uint8_t* pdata, uint16_t size, uint8_t *p_res, uint16_t *p_size)
{
    if( size != 0)
    {
        return PBD_ERR_INVALID_LENGTH;
    }

//    uint32_t flag = iqw_app_factory_test_get_flag();
//    p_res[0] = (uint8_t)(flag >> 0);
//    p_res[1] = (uint8_t)(flag >> 8);
//    p_res[2] = (uint8_t)(flag >> 16);
//    p_res[3] = (uint8_t)(flag >> 24);
    *p_size = 4;

    return PBD_SUCCESS;
}

#endif 
